Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

feat: squash with prefix #291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: squash with prefix #291

wants to merge 2 commits into from

Conversation

kamilsk
Copy link

@kamilsk kamilsk commented May 31, 2022

Fix issue #288.

Temporary: how to support this feature in your env

$ go mod edit -replace=github.com/mitchellh/[email protected]=github.com/kamilsk/mapstructure@4650365

Tested with viper and pflag https://github.com/octomation/maintainer/blob/dbfaab2b34ba9d2363d3e665b20c8bb5783581b1/internal/config/tool_test.go#L40-L87

@@ -518,13 +518,13 @@ func (d *Decoder) decodeBasic(name string, data interface{}, val reflect.Value)
copied = true

// Make *T
copy := reflect.New(elem.Type())
clone := reflect.New(elem.Type())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent shadowing of built-in function copy

@@ -857,7 +857,7 @@ func (d *Decoder) decodeMapFromMap(name string, dataVal reflect.Value, val refle
valElemType := valType.Elem()

// Accumulate errors
errors := make([]string, 0)
errs := make([]string, 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent shadowing of errors package

}

return nil
}

func (d *Decoder) decodeMapFromStruct(name string, dataVal reflect.Value, val reflect.Value, valMap reflect.Value) error {
func (d *Decoder) decodeMapFromStruct(_ string, dataVal reflect.Value, val reflect.Value, valMap reflect.Value) error {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused name argument

@kamilsk
Copy link
Author

kamilsk commented Jul 5, 2022

@mitchellh, hi! I'm sorry for the ping. Is there a chance to get feedback here?

if prefix == "" {
return s
}
return prefix + "_" + s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the _? Wouldn't it be more flexible to just add it to the prefix?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be more flexible if added to DecoderConfig. I preferred to make it simple.

Also, for me, it's just the same approach as https://cs.opensource.google/go/go/+/refs/tags/go1.21.3:src/path/path.go;l=162-180

@alfa-alex
Copy link

Any chances on getting this merged in the foreseeable feature? I'm also highly looking forward to this feature!

Thank you, @kamilsk, for submitting this!

}

type GitHub struct {
Git `mapstructure:"git,squash"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems not possible to use another name than git here. For example if you rename this to

Suggested change
Git `mapstructure:"git,squash"`
Git `mapstructure:"gitx,squash"`

and update the input below accordingly (to GITHUB_GITX_REMOTE), the test panics.

Is this the desired behavior? I would have expected to be able to use any name here instead of just the name of the embedded struct.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants